package com.lt.basic.project.mino.controller.login;

import com.lt.basic.project.application.config.local.ProThreadLocal;
import com.lt.basic.project.application.service.mino.login.ILoginService;
import com.lt.basic.project.common.aop.NotLogin;
import com.lt.basic.project.common.core.AjaxResult;
import com.lt.basic.project.pojo.validate.mino.login.LoginCodeValidate;
import com.lt.basic.project.pojo.validate.mino.login.LoginPhoneValidate;
import com.lt.basic.project.pojo.vo.mino.login.LoginTokenVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 登录管理
 * @author LT
 */
@Slf4j
@RestController
@RequestMapping("/mino/login")
@Api(tags = "登录管理")
public class LoginController {

    @Resource
    ILoginService iLoginService;

    /**
     * 手机登录
     * @param loginPhoneValidate
     * @return LoginTokenVo
     */
    @NotLogin
    @PostMapping("/mobile/login")
    @ApiOperation(value="手机登录")
    public AjaxResult<LoginTokenVo> mobileLogin(@Validated @RequestBody LoginPhoneValidate loginPhoneValidate) {
        Integer terminal = ProThreadLocal.getTerminal();
        String mobile = loginPhoneValidate.getMobile();
        String code = loginPhoneValidate.getCode();

        LoginTokenVo vo = iLoginService.mobileLogin(mobile, code, terminal);
        return AjaxResult.success(vo);
    }

    /**
     * 微信登录
     * @param loginCodeValidate
     * @return LoginTokenVo
     */
    @NotLogin
    @PostMapping("/mnp/login")
    @ApiOperation(value="微信登录")
    public AjaxResult<LoginTokenVo> mnpLogin(@Validated @RequestBody LoginCodeValidate loginCodeValidate) {
        Integer terminal = ProThreadLocal.getTerminal();
        String code = loginCodeValidate.getCode();

        LoginTokenVo vo = iLoginService.mnpLogin(code, terminal);
        return AjaxResult.success(vo);
    }

}
